define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    var Controller = {
        index: function () {
            var supplier_id = GetQueryString('supplier_id');
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'activity/index?supplier_id='+supplier_id,
                    add_url: 'activity/add',
                    edit_url: 'activity/edit',
                    del_url: 'activity/del',
                    multi_url: 'activity/multi',
                    table: 'activity',
                }
            });

            var table = $("#sitetable");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                       /* {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},*/
                        {field: 'supplier_name', title: '活动商名称'},
                        {field: 'poster', title: __('Poster'), operate:false,formatter: Table.api.formatter.image},
                        {field: 'name', title: __('Name')},
                        {field: 'address', title: __('Address')},
                        {field: 'max_num', title: __('Max_num')},
                        {field: 'fee', title: __('Fee'),visible: false},
                        {field: 'is_house_text', title: __('Is_house'), operate:false},
                        {field: 'category_text', title: __('Category'), operate:false},
                        {field: 'plan', title: __('plan'), operate:false},
                        {field: 'notes', title: __('Notes'), operate:false},
                        {field: 'site_name', title: __('Site_name')},
                        {field: 'site_address', title: __('Site_address')},
                        {field: 'time', title: __('Time'), formatter: Table.api.formatter.test},
                       /* {field: 'create_time', title: __('Create_time'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},*/
                        {field: 'create_time', title: __('create_time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', options: {}},
                        {field: 'update_time', title: __('Update_time'), formatter: Table.api.formatter.datetime, operate:false},

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter: {
                test: function (value, row, index) {
               /*   alert("value = " + value);
                   alert("row = " + row);
                    alert("index = " + index);*/
                    return index;
                },
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});